﻿using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace Super.Admin.Utils.ThemeManager
{
    public class ThemeViewModelBase
    {
        public event PropertyChangedEventHandler PropertyChanged;
        protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
        protected bool SetProperty<T>(ref T field, T value, [CallerMemberName] string propertyName = null)
        {
            if (EqualityComparer<T>.Default.Equals(field, value)) return false;
            field = value;
            OnPropertyChanged(propertyName);
            // 只有当单例已完成初始化时才保存
            if (ThemeSettingHelper._instance.IsValueCreated)
            {
                if (ThemeSettingHelper.Instance.IsApplyTheme)
                    ThemeSettingHelper.Instance.Save();
            }
            return true;
        }
    }
}
